class RMASMError(Exception):
    pass


class RLexerError(RMASMError):
    def __init__(self, source: str, line_num: int, message: str):
        source = f"在 {source} 中的" if source else ""
        super().__init__(f'[{source}第 {line_num} 行] {message}')


class RGrammarError(RMASMError):
    def __init__(self, source: str, line_num: int, message: str):
        source = f"在 {source} 中的" if source else ""
        super().__init__(f'[{source}第 {line_num} 行] {message}')


class RTranslateError(RMASMError):
    def __init__(self, source: str, line_num: int, message: str):
        source = f"在 {source} 中的" if source else ""
        super().__init__(f'[{source}第 {line_num} 行] {message}')

    pass


class RKeyVarNotFound(RTranslateError):

    def __init__(self, source: str, line_num: int, key: str):
        super().__init__(source, line_num, f"不存在的特殊变量：{key}")
        self.key = key
